using System;
using SharpObjects.EventBus;
using SharpObjects.Shared.ApplicationEvents;

namespace SharpObjects.Shared.Proxies
{
    public class LogProxy
    {
        protected IEventBus eventBus;

        protected LogProxy()
        {
            this.eventBus = null;
        }

        public LogProxy(IEventBus eventBus)
        {
            this.eventBus = eventBus;
        }

        public void Write(LogCategoryName categoryName, Origin origin, string message, params object[] messageArgs)
        {
            LogApplicationEvent logApplicationEvent = new LogApplicationEvent()
                                                          {
                                                              CategoryName = categoryName,
                                                              Message = string.Format(message, messageArgs),
                                                              Origin = origin
                                                          };
            eventBus.Publish(logApplicationEvent);
        }

        public void Write(LogCategoryName categoryName, Origin origin, Exception ex, bool appendStackTrace = true)
        {
            LogExceptionApplicationEvent logExceptionApplicationEvent = new LogExceptionApplicationEvent()
                                                                            {
                                                                                CategoryName = categoryName,
                                                                                Origin = origin,
                                                                                Exception = ex,
                                                                                AppendStackTrace = appendStackTrace
                                                                            };
            eventBus.Publish(logExceptionApplicationEvent);
        }
        
    }
}